package com.itheima.包装类.二分查找;

import java.util.Arrays;

public class MyBinarySearchDemo2 {

  /*  public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int number = 3;
        int index = binarySearchForIndex(arr, number);
        System.out.println(index);
    }
        private static int binarySearchForIndex ( int[] arr, int number){
            int min = 0;
            int max = arr.length - 1;
            while (min <= max) {
                int mid = (min + max) >> 1;
                if (arr[mid] > number) {
                    max = min - 1;
                } else if (arr[mid] < number) {
                    min = mid + 1;
                } else {
                    return mid;
                }
            }
        return -1;
        }*/
  public static void main(String[] args) {
      int[]arr={11,22,33,44,55,66};
     /* int number=66;
          int index=binarySearchForIndex(arr,number);
      System.out.println(index);*/


      System.out.println(Arrays.binarySearch(arr, 33));


  }
 /*   private static int binarySearchForIndex(int[]arr,int number){
      int min=0;
      int max=arr.length-1;
      //循环遍历查找min<=max
        while(min<=max){
            //计算出中间位置mid
            int mid=(min+max)>>1;
            if (arr[mid]>number){
                max=mid-1;
            }else if (arr[mid]<number){
                min=mid+1;
            }else {
                return mid;
            }
        }
        return -1;
    }*/




}
